import request from '@/utils/request'

// 注册接口
export const userRegisterService = ({ username, password, email }) =>
  request.post('/users/register', { username, password, email })

// 登录接口
export const userLoginService = ({ username, password }) =>
  request.post('/users/login', { username, password })

// 忘记密码接口 需要返回一个密码信息
export const userForgetPassword = () => {
  console.log()
}

// 获取学生全部信息
export const userAllService = () => request.get('/students/all')
// export const userAllService = async () => {
//   try {
//     const response = await request.get('/students/all')
//     console.log('API响应数据：', response.data) // 添加调试语句
//     if (response && response.status === 200 && response.data) {
//       return response.data
//     } else {
//       throw new Error('获取用户信息失败：无效的响应数据')
//     }
//   } catch (error) {
//     throw new Error('获取用户信息失败：' + error.message)
//   }
// }

// 分页信息
export const userGetInfoService = ({ type, current, size }) =>
  request.post('/students/page', {
    type,
    current,
    size
  })
// 删除学生
export const userDelService = (params) =>
  request.delete('/students/delete', { data: params })
// 添加学生
export const userAddService = (data) => request.post('/students/add', data)
// 编辑学生
export const userEditService = (params) =>
  request.post('/students/update', params)
// 获取学生详情
export const userDetailService = (student_name) =>
  request.get('/students/byName', { params: { student_name } })
// GPa查询
export const userGpaService = ({ studentGrade, minGpa, maxGpa }) =>
  request.post('/students/query', { studentGrade, minGpa, maxGpa })

// desc排序
export const userGetListServicedesc = (params) =>
  request.get(`/students/desc/${params.current}/${params.size}`, {
    current: params.current,
    size: params.size
  })
// asc 排序
export const userGetListServiceasc = (params) =>
  request.get(`/students/asc/${params.current}/${params.size}`, {
    current: params.current,
    size: params.size
  })

export const userGpaAddService = ({
  id,
  studentId,
  oneGpa,
  twoGpa,
  threeGpa,
  fourGpa
}) =>
  request.post('/gpas/update', {
    id,
    studentId,
    oneGpa,
    twoGpa,
    threeGpa,
    fourGpa
  })
